home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 85 / CD Temático 40 Febrero 2004.iso / DOS / ntfs / user / ntmkdir.c < prev    next >
Encoding:
C/C++ Source or Header  |  2001-02-15  |  2.2 KB  |  116 lines

  1. /*
  2.  *  ntmkdir.c
  3.  *
  4.  *  Copyright (C) 1998 Martin von L÷wis
  5.  */
  6.  
  7. #ifdef HAVE_CONFIG_H
  8. #include "config.h"
  9. #endif
  10.  
  11. #include <stdio.h>
  12. #include <ctype.h>
  13. #ifdef HAVE_GETOPT_H
  14. #include <getopt.h>
  15. #else
  16. #define getopt_long(a,v,o,ol,x)        getopt(a,v,o)
  17. #endif
  18. #ifdef HAVE_UNISTD_H
  19. #include <unistd.h>
  20. #endif
  21. #include <stdlib.h>
  22. #include <string.h>
  23. #include "ntfstypes.h"
  24. #include "struct.h"
  25. #include "util.h"
  26. #include "support.h"
  27. #include "nttools.h"
  28. #include "dir.h"
  29. #include "inode.h"
  30.  
  31. char *short_opts="f:hV";
  32. #ifdef HAVE_GETOPT_H
  33. struct option options[]={
  34.     {"filesystem",1,0,'f'},
  35.     {"version",0,0,'V'},
  36.     {0,0,0,0}
  37. };
  38. #endif
  39.  
  40. char usage_str[]=
  41. "ntmkdir: Creates a new directory\n"
  42. "ntmkdir [OPTIONS] path\n"
  43. "  --filesystem, -f device   Use device\n"
  44. "  --help, -h                Display this message\n"
  45. "  --version, -v             Display version\n"
  46. ;
  47.  
  48.  
  49. void usage(void)
  50. {
  51.     fprintf(stderr,usage_str);
  52. }
  53.  
  54.  
  55. int main(int argc,char *argv[])
  56. {
  57.     int c;
  58.     char *device=0;
  59.     char *name;
  60.     ntfs_volume *volume;
  61.     ntfs_inode ino,new;
  62.     int inum,bias=0;
  63.     unsigned int type=ngt_nt;
  64.     unsigned int charset=nct_utf8;
  65.     extern int opterr,optind;
  66.     extern char* optarg;
  67.     int error;
  68.  
  69.     opterr=1;
  70.     while((c=getopt_long(argc,argv,short_opts,options,NULL))>0)
  71.         switch(c)
  72.         {
  73.         case 'f': device=optarg;break;
  74.         case 'h': usage();exit(0);break;
  75.         case 'V': printf("ntmkdir " NTFS_VERSION "\n");exit(0);break;
  76.         default: usage();exit(1);
  77.         }
  78.     name=argv[optind];
  79.     if(!name){
  80.         usage();
  81.         exit(1);
  82.     }
  83.     volume=ntfs_open_volume(device,bias,1,0);
  84.     if(!volume)return 1;
  85.     volume->ngt=type;
  86.     volume->nct=charset;
  87.     /* walk the directory */
  88.     inum=5;
  89.     do{
  90.         char *next;
  91.         if(ntfs_init_inode(&ino,volume,inum))
  92.             fprintf(stderr,"error opening %s\n",name);
  93.         next=strpbrk(name,NTFS_PATH_SEP);
  94.         if(!next)
  95.             break;
  96.         *next='\0';
  97.         next++;
  98.         inum=ntfs_find_file(&ino,name);
  99.         if(inum==-1){
  100.             printf("%s not found\n",name);
  101.             return 1;
  102.         }
  103.         name=next;
  104.     }while(1);
  105.     error = ntfs_mkdir(&ino,name,strlen(name),&new);
  106.     if (error)
  107.         printf("%s: %s\n",name,strerror(error));
  108.     return 0;
  109. }
  110.  
  111. /*
  112.  * Local variables:
  113.  * c-file-style: "linux"
  114.  * End:
  115.  */
  116.